﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Animation;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Media3D;
using System.Data;
using System.Reflection;
using System.Collections;
using System.Windows.Media;
using System.Globalization;
using CrazyWorship1.PropertyHandler;
using System.Windows.Shapes;
namespace CrazyWorship1.Transitions
{
    public class CharacterFadeIn : BaseTransitionIn
    {
        DoubleAnimation fade;
        public override void SetupTransition()
        {
            fade=new DoubleAnimation();
            fade.To=1;
            fade.Duration=new Duration(new TimeSpan(0,0,0));
            DoubleAnimation pause = new DoubleAnimation();
            pause.Duration=new Duration(new TimeSpan(0,0,0,0,100));
            //storyboard.Children.Add(anim);
        }
        [DataAttribute("FadeLength", typeof(IntPropertyHandler),"CharacterFadeInDefaultFadeLength")]
        public string FadeLength
        {
            get
            {
                return fade.Duration.TimeSpan.Seconds.ToString(CultureInfo.InvariantCulture);
            }
            set
            {
                fade.Duration = new TimeSpan(0, 0, 0, Convert.ToInt32(value, CultureInfo.InvariantCulture), 0);
            }
        }
        [DataAttribute("FadeTo", typeof(IntPropertyHandler), "CharacterFadeInDefaultFadeTo")]
        public string FadeTo
        {
            get
            {
                return fade.To.ToString();
            }
            set
            {
                fade.To = Convert.ToDouble(value, CultureInfo.InvariantCulture);
            }
        }
        public override void Go()
        {
            base.Go();
       //     Visual tb = CurrentLyricTextBlock;
          //  List<DoubleAnimation> fader = new List<DoubleAnimation>();
           // tb.Opacity = 1;
            //for (int i = 0; i < tb.Text.Length; ++i)
            //{
            //    fader.Add(new DoubleAnimation());
            //    fader[i].Duration = new Duration(new TimeSpan(0,0,1));
            //    fader[i].BeginTime =new TimeSpan(0,0,0,0,i*100);
            //    fader[i].From = 0;
            //    fader[i].To = 0.1;
                
            //    TextEffect effect = new TextEffect();
            //    effect.PositionCount = 1;
            //    effect.PositionStart = i;
                
            //    TransformGroup transGrp = new TransformGroup();
            //    TranslateTransform tf = new TranslateTransform();
            //    transGrp.Children.Add(tf);
            //    effect.Transform = transGrp;
            //    tb.TextEffects.Add(effect);

            //    tf.BeginAnimation(TranslateTransform.YProperty, fader[i]);

           
            
            //}

        //   Storyboard.SetTargetProperty(storyboard.Children[0], new PropertyPath(TextBlock.OpacityProperty));
       //    storyboard.Begin();
        }
      //  private void AddTextEffectForCharacter(int charIndex,TextBlock tb){
           
    //    }
     //   private void AddFadeAnimation(int charIndex)
    //    {
    //        this.SetBeginTime(fade, charIndex);
     //       string path = String.Format("TextEffects[{0}].Transform.Children[1].Opacity", charIndex);
     //       //TextEffects[charIndex].Transform.Children[1].Opacity.
     //       PropertyPath propPath = new PropertyPath(path);
     //       

     //   }
  //      private void SetBeginTime(Timeline anim, int charIndex)
    //    {
     //       double totalMs = anim.Duration.TimeSpan.TotalMilliseconds;
   //             double offset=totalMs/10;
     //       double resolvedOffset=offset*charIndex;
    //        anim.BeginTime=TimeSpan.FromMilliseconds(resolvedOffset);
    //    }
    }
   
}
